package svc

import (
	"cloud-disk/core/internal/config"
	"cloud-disk/core/internal/middleware"
	"cloud-disk/core/model"
	"cloud-disk/tool"
	"github.com/zeromicro/go-zero/rest"
)

type ServiceContext struct {
	Config              config.Config
	UserModel           model.UserBasic
	RepositoryPoolModel model.RepositoryPool
	UserRepostioryModel model.UserRepostiory
	ShareBasicModel     model.ShareBasic
	Email               *tool.EmailClient
	Cos                 *tool.Cos
	Auth                rest.Middleware
}

func NewServiceContext(c config.Config) *ServiceContext {
	return &ServiceContext{
		Config:              c,
		UserModel:           model.UserBasic{},
		RepositoryPoolModel: model.RepositoryPool{},
		UserRepostioryModel: model.UserRepostiory{},
		ShareBasicModel:     model.ShareBasic{},
		Email: tool.NewEmailClient(&tool.EmailConfig{
			Addr:     c.Email.Addr,
			UserName: c.Email.UserName,
			Password: c.Email.EmailPassword,
			Host:     c.Email.Host,
		}),
		Cos: tool.NewCos(&tool.CosConfig{
			Addr:      c.Cos.Addr,
			SecretID:  c.Cos.SecretID,
			SecretKey: c.Cos.SecretKey,
		}),
		Auth: middleware.NewAuthMiddleware().Handle,
	}
}
